package com.dycong.common.IO.calculator.bio;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
/**
 * BIO
 * @author yangtao__anxpp.com
 * @version 1.0
 */
public final class ServerNormal {

	private static int DEFAULT_PORT = 12345;

	private static ServerSocket server;

	public static void start() throws IOException{

		start(DEFAULT_PORT);
	}

	public synchronized static void start(int port) throws IOException{
		if(server != null) return;
		try{

			server = new ServerSocket(port);
			System.out.println("server listening port: " + port);
			Socket socket;

			while(true){
				socket = server.accept();

				new Thread(new ServerWriter(socket)).start();
			}
		}finally{

			if(server != null){
				System.out.println("�������ѹرա�");
				server.close();
				server = null;
			}
		}
	}
}